<?php
namespace includes;
/**
 * Description of Form
 *
 * @author John
 */
class HtmlForm {
    private $dbTable;
    private $primaryKey;
    
    
    public function __construct( $dbTable, $primaryKey ) {
	$this->dbTable = $dbTable;
	$this->primaryKey = $primaryKey;
	global $database;
    }
    
    public function addToForm($formElement) {
	
    }
    
    public function addLabelFor($field, $value) {
	
    }
    
    public function addTextField($name, $class, $id, $required) {
	if($_POST) {
	    $value = $_POST[$name];
	}
	elseif(isset($_GET[$this->primaryKey])) {
	    $sql = "SELECT {$name} FROM {$this->dbTable} WHERE {$this->primaryKey} = {$_GET[$this->primaryKey]} LIMIT 1;";
	    //$result = mysql_query($sql) or die("Error while executing query: ".  mysql_error());
	    $database->query( $sql );
	    
	    
	    mysql_num_rows($result) > 0 ? $row = mysql_fetch_assoc ($result) : $row = '';
	    $value = $row[$name];
	}
	else {
	    $value = '';
	}
	
	$required = $required ? '*' : '';
	
	return "$required<input type='text' name='$name' class='$class' id='$id' />";
    }
}

?>
